$(document)
    .ready(
        function() {
            //ClearIDCard();
            //---
            Init();
            //DelPrinterJob();
            var pstate='true';
            pstate=m607state(GetStatus());
            if(pstate!='true'){
                $(document.body).append("<div class='alert fade in' id='btn_warn'><div class='warn_div'><font class='font18' id='warn'>请联系工作人员。打印机"+pstate+"，暂停使用。</font></div></div>");
            }else{
                autoCard();
                //打开串口及签章机
                var flag= OpenCom("2");
                if(flag==0){
                    RunStamp(2);
                    StopStamp();
                }
            }


        });

var interval;

function autoCard(){
    //开启身份证读卡功能
    rdcard.ReadCard2();
    //设置读卡后自动赋值
    interval = setInterval(readCard, 500);
}

function Idcard(){

}

function readCard(){

    var idcard=rdcard.CardNo;
    if(idcard){
        //读卡成功停止读卡
        clearInterval(interval);
        rdcard.EndRead();
        //赋值
        document.getElementById("partyName").value = rdcard.NameS;//姓名
        document.getElementById("gender").value = rdcard.Sexl;//性别
        document.getElementById("nation").value = rdcard.Nationl;//民族
        document.getElementById("bornDay").value =  rdcard.Born;//生日年月日
        document.getElementById("certAddress").value = rdcard.Address;//家庭住址
        document.getElementById("certNumber").value = rdcard.CardNo;//身份证号
        document.getElementById("certOrg").value = rdcard.Police;//签发机关

        document.getElementById("effDate").value = rdcard.ActivityLFrom;
        document.getElementById("expDate").value = rdcard.ActivityLTo;
        var photo=rdcard.BMPBuffer;
        var nonage=$("#nonage").val();
        if(nonage){
            document.getElementById("agentHead").src = 'data:image/jpeg;base64,' + rdcard.BMPBuffer;
            $("#nonageIngress").html("");
        }else{
            document.getElementById("dispHead").src = 'data:image/jpeg;base64,' + rdcard.BMPBuffer;
        }

        //清空刷卡信息
        ClearIDCard();

        $("#card_read").click();
    }
}
//返回
function back(){
    $("#certNumber").val("");
    $("#name").html("");
    $("#sex").html("");
    $("#nation_").html("");
    $("#birthday").html("");
    $("#address").html("");
    $("#idcard").html("");
    $("#banum").val("");
    $("#phone").val("");
    $("#header_name_pay").html("");
    $("#validation").val("");
    $("#choice").val("");
    $("#crdiv").attr("class","modal_ modal_stamp");
    $("#sfzdiv").attr("class","modal_1 modal  hide");
    $("#div_key").attr("class","modal_key modal hide");
    $("#dy_validation").val("");
    $("#partyName").val("");//姓名
    $("#gender").val("");//性别
    $("#nation").val("");//民族
    $("#bornDay").val("");//生日年月日
    $("#certAddress").val("");//家庭住址
    $("#certNumber").val("");//身份证号
    $("#certOrg").val("");//签发机关

    $("#effDate").val("");;
    $("#expDate").val("");;
    $("#fq_dy").attr("class","hide");
    agentBack();
    autoCard();
}

//返回
function agentBack(){

    $("#agentHead").attr("src","");
    $("#agentsex").html("");
    $("#agentsexnation").html("");
    $("#agentsexbirthday").html("");
    $("#agentsexaddress").html("");
    $("#agentidcard").html("");
    $("#nonage_card").val("");
    $("#nonageIngress").attr("class","button_close");
    $("#nonagediv").attr("class","hide");
    $(".oneselftr").attr("class","oneselftr");
    $(".agenttr ").attr("class","agenttr hide");
    $("#confirm_agent").attr("disabled",false);
    nonageBack();
}

function ClearIDCard() {

    rdcard.ClearAll();
    rdcard.DeleteOutputFile();
    rdcard.DeleteAllPicture();

    return true;
}